package base

import (
	model "beesoft.ink/application/text/app/model/base"
	"fmt"
	"github.com/spf13/viper"
	"os"
	"runtime"
	"strings"
)

func LoadConfig() {
	configPath := "config"
	if os.Getenv("ENV") == model.EnvTypeDevelopment {
		configPath = model.CodePath + "/config"
	}

	viper.SetConfigName("config")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(configPath)

	if err := viper.ReadInConfig(); err != nil {
		panic(fmt.Errorf("fatal error config file: %w", err))
	}
}
func InitCodePath() {
	_, file, _, ok := runtime.Caller(0)
	if !ok {
		return
	}

	model.CodePath = strings.ReplaceAll(file, "/app/service/base/base.go", "")
}
